package com.ithanwen.controller;

import com.ithanwen.mapper.EmpExprMapper;
import com.ithanwen.pojo.*;
import com.ithanwen.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created By tony
 * <br/>Date: 2025/7/10 14:59
 * <br/>Description:
 */

@RestController
public class EmpController {

    @Autowired
    private EmpService empService;

    @Autowired
    private EmpExprMapper empExprMapper;

    @GetMapping("/emps")
    public Result list(EmpQueryParam empQueryParam){
        PageResult<Emp> pageResult = empService.page(empQueryParam);
        return Result.success(pageResult);
    }

    @PostMapping("/emps")
    public Result save(@RequestBody Emp emp){
        empService.save(emp);
        return  Result.success();
    }

    @DeleteMapping("/emps")
    public Result delete(@RequestParam("ids") List<Integer> ids){
        empService.deleteByIds(ids);
        return Result.success();
    }

    @PutMapping("/emps")
    public Result update(@RequestBody Emp emp) {
        empService.update(emp);
        return Result.success();
    }

    @GetMapping("/emps/{id}")
    public Result findById(@PathVariable Integer id){
        return Result.success(empService.findById(id));
    }

    @RequestMapping(value = "/emps/list",method = RequestMethod.GET)
    public Result getList(){
        return Result.success(empService.findall());
    }
}
